package com.ysd.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.ysd.crm.entity.Students;
import com.ysd.crm.entity.seach.StudentsSeach;
import com.ysd.crm.service.StudentsService;
import com.ysd.crm.utils.LayResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@RequestMapping("/students")
@Api
@RestController
public class StudentsController {
	@Autowired
	private StudentsService studentsService;
	
	@ApiOperation("多条件分页查询 Students ytt")
	@GetMapping("getStuByWhere")
	private Object getStuByWhere(StudentsSeach s) {
		s.setPage((s.getPage()-1)*s.getLimit());
		List<Students> list = studentsService.findStuByWhere(s);
		int count = studentsService.findStuCount(s);
		if(list != null) {
			return LayResult.toClient("0", "", count, list);
		}
		return LayResult.toClient("1", "");
	}
	
	
	@RequestMapping("insertStudent")
	public Object insertStudent(Students s) {
		int n=studentsService.fisertStudens(s);
		if (n>0) {
			return LayResult.toClient("0", "添加成功");
		} else {
			return LayResult.toClient("1", "添加失败");

		}
	}
	@ApiOperation("修改-gmw")
	@PostMapping("updaStu")	
	public Object updaStu(Students s) {
		
		int n=studentsService.updateStu(s);
		if(n>0) {
			return LayResult.toClient("0", "修改成功");
		}
		return LayResult.toClient("1", "修改失败");
	}
	@ApiOperation("删除-gmw")
	@PostMapping("delStu")	
	public Object delStu(Students s) {
		int n=studentsService.deleteStu(s);
		if(n>0) {
			return LayResult.toClient("0", "删除成功");
		}
		return LayResult.toClient("1", "删除失败");
	}
}
